<template>
  <el-dialog title="加扣款" :visible.sync="visible" :close-on-click-modal="false"
    :before-close="handleCloseDialog" width="680px">
    <el-form :model="dataObject" :rules="rules" ref="adminForm" label-width="100px" size="small">
      <el-form-item label="用户名称：" prop="username">
        <el-input v-model="dataObject.username" :disabled="isEdit" clearable placeholder="请输入用户名称"></el-input>
      </el-form-item>
      <el-form-item label="增加：" prop="deductionStatus">
         <el-select v-model="dataObject.deductionStatus" placeholder="请选择状态">
            <el-option
              v-for="item in deductionStatusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="金额：" prop="amount">
        <el-input v-model="dataObject.amount" type="number" placeholder="请输入金额" clearable></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleConfirmDialog('adminForm')" size="mini">确 定</el-button>
      <el-button @click="handleCloseDialog" size="mini">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { createAdmin, updateAdmin, getAdmin } from '@/api/login';
import { createNamespacedHelpers } from "vuex";

const { mapState } = createNamespacedHelpers("member");

const defaultObject = {
  username: "",
  deductionStatus: "1",
  amount: ''
};

export default {
  name: "deductionDialog",
  data() {
    return {
      visible:true,
      loading: false,
      dataObject: Object.assign({}, defaultObject)
    };
  },
  props: {
    row: {
      type: Object,
      default: {}
    }
  },
  computed: {
    ...mapState({
      rules: state => state.rules,
      deductionStatusOptions: state => state.routes.deductionStatus
    })
  },
  mounted() {
    if (this.isEdit) {
      getAdmin(this.dataId).then(response => {
        this.dataObject = response.data;
      });
    } else {
      this.dataObject = Object.assign({}, defaultObject);
    }
  },
  methods: {
    handleCloseDialog() {
      this.$emit("handle-cancel");
    },
    handleConfirmDialog(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          createAdmin(this.dataObject).then(response => {
            this.resetForm(formName);
            this.$message({
              message: "提交成功",
              type: "success",
              duration: 1000
            });
            this.$emit("handle-confirm");
          });
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.dataObject = Object.assign({}, defaultObject);
    }
  }
};
</script>
<style scoped>
.user-container {
  display: flex;
  justify-content: space-between;
  flex-wrap: nowrap
}

.left-box {
  border: 1px solid #DCDFE6;
  padding: 4px;
}

.right-box {
  border: 1px solid #DCDFE6;
  padding: 4px;
  margin-left: 8px;
  flex-grow: 1;
}

.ritht-box-top {
  border: 1px solid #DCDFE6;
  display: flex;
  justify-content: space-between;
  flex-wrap: nowrap;
  justify-items: center;
  padding: 0px 6px;
  border-radius: 4px;
}

.ritht-box-top span {
  font-weight: 100;
  line-height: 26px;
}

.ritht-box-content {
  height: 400px;
  overflow: auto;
  border: 1px solid #DCDFE6;
  margin-top: 4px;
}

.tree-list {
  height: 400px;
  overflow: auto;
  border: 1px solid #DCDFE6;
  margin-top: 4px;
}

.tag-item {
  margin: 4px 0px 0px 4px;

}
</style>